import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { Result } from "@/api/community";

export type UserResult = {
  code: number;
  msg?: string;
  data?: {
    /** 用户名 */
    username: string;
    /** 当前登陆用户的角色 */
    role: Array<string>;
    /** `token` */
    token: string;
  };
};
/** 登录 */
export const getLogin = (data?: object) => {
  return http.request<UserResult>("post", baseUrlApi("owner/login"), { data });
};
/** 获取用户列表 */
export const getUserList = (current?: number, username?: string) => {
  return http.request<Result>(
    "get",
    baseUrlApi("owner/getUserList?current=" + current + "&username=" + username)
  );
};
/** 获取用户信息 */
export const getUserInfo = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/ownerInfo/" + data));
};
/** 获取用户身份 */
export const getUserRole = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/getUserRole/" + data));
};
/** 根据用户ID获取用户名下房产 */
export const getUserHouseListByUserId = (data?: any) => {
  return http.request<Result>(
    "get",
    baseUrlApi("owner/getUserHouseList/" + data)
  );
};
/** 根据用户ID重置用户密码 */
export const setUserPasswordByUserId = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/rePassword/" + data));
};
/** 根据用户ID获取用户名下商铺 */
export const getUserShopsListByUserId = (data?: any) => {
  return http.request<Result>(
    "get",
    baseUrlApi("owner/getUserShopsList/" + data)
  );
};
/** 获取个人名下所有房产 */
export const getOwnerHouseList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/getOwnerHouseList"));
};
/** 获取业主名下计量数据 */
export const getOwnerHouseMeterList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/getMeterList?houseId=" + data.houseId + "&meterType=" + data.meterType));
};
/** 创建订单 */
export const createOrder = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/order/createOrder?orderId=" + data));
};
/** 支付订单 */
export const payOrder = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/order/payOrder?orderId=" + data));
};
/** 检查订单支付状态 */
export const payCheck = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/order/payCheck?orderId=" + data));
};
/** 获取名下商铺 */
export const getShopsList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/getUserShopsList?residentialId=" + data.residentialId + "&name=" + data.name));
};
/** 获取所有小区 */
export const getResidentialList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/getResidentialList"));
};
/** 编辑个人商铺信息 */
export const editOwnerShops = (data?: any) => {
  return http.request<Result>("post", baseUrlApi("owner/shops/edit"), { data });
};
export const getParkingList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/parking/list?name=" + data));
};
export const getHouseList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/house/list?residentialId=" + data));
};
/** 获取报修列表 */
export const getOwnerRepairList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/repair/list?residentialId=" + data.residentialId + "&name=" + data.name));
};

export const getOwnerComplainList = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/complain/list?residentialId=" + data.residentialId + "&name=" + data.name));
};
/** 投诉评分 */
export const scoreComplain = (data?: any) => {
  return http.request<Result>("post", baseUrlApi("owner/complain/score"), { data });
};
/** 获取所有物业 */
export const getAdmin = (data?: any) => {
  return http.request<Result>("get", baseUrlApi("owner/getAdmin"));
};
export const addComplain = (data?: any) => {
  return http.request<Result>("post", baseUrlApi("owner/addComplain"), { data });
};
export const deleteOwnerComplain = (data: number) => {
  return http.request<Result>("get", baseUrlApi("owner/deleteComplain/" + data));
};
/** 获取首页统计数据 */
export const getTotalData = () => {
  return http.request<Result>("get", baseUrlApi("owner/getTotalData"));
};
/** 获取投诉数量 */
export const getComplainTotal = () => {
  return http.request<Result>("get", baseUrlApi("owner/getComplainTotal"));
};
/** 获取投诉比例 */
export const getWeekComplainTotal = () => {
  return http.request<Result>("get", baseUrlApi("owner/getWeekComplainTotal"));
};
export const getCommonLightTotal = () => {
  return http.request<Result>("get", baseUrlApi("owner/getCommonLightTime"));
};
/** 发布报修 */
export const addRepair = (data?: any) => {
  return http.request<Result>("post", baseUrlApi("owner/repair/add"), { data });
};
